package com.gec.utils;

public class PageModel {
    //当前页码数
    private int pageIndex;
    //每页显示数量
    public static final int pageSize=2;
    //总页数
    private int totalPageSum;
    //总记录数
    private int totalRecoreSum;

    //当前页码数
    public int getPageIndex() {
        //如果输入的页码是负数
        this.pageIndex=this.pageIndex <= 0 ? 1 : this.pageIndex;
        //如果输入的页码大于总页数
        this.pageIndex=this.pageIndex >= getTotalPageSum() ? getTotalPageSum() : this.pageIndex;
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public static int getPageSize() {
        return pageSize;
    }
    //总页数
    public int getTotalPageSum() {
        //总记录数%每页显示数量 如果整除，就直接除，不能整除，则加1
        this.totalPageSum=getTotalRecoreSum() % getPageSize() ==0 ? getTotalRecoreSum()/getPageSize() : getTotalRecoreSum()/getPageSize()+1;
        return totalPageSum;
    }

    //起始行
    public int getStartRow(){
        //(当前页面-1)*每页数量
        int start=(getPageIndex()-1) >=1 ? (getPageIndex()-1)*getPageSize() : 0;
        return start;
    }

    public void setTotalPageSum(int totalPageSum) {
        this.totalPageSum = totalPageSum;
    }
    //总记录数
    public int getTotalRecoreSum() {
        return totalRecoreSum;
    }

    public void setTotalRecoreSum(int totalRecoreSum) {
        this.totalRecoreSum = totalRecoreSum;
    }
}
